

set more off
mat drop _all


use "$path_data/data/temp/attrition_check.dta", clear





*** Test for DT
preserve
drop if DT_per_min_pre == .
drop if DT_per_min_post == .
drop if wrongDT == 1






foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_DT = r(StatTotal)
}

foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_DT = r(StatTotal)
}



matrix n_dif1_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif1_DT[1,`i'] = n_tr1_DT[1,`i'] + n_ct1_DT[1,`i']
}


matrix mean_dif1_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif1_DT[1,`i'] = mean_tr1_DT[1,`i'] - mean_ct1_DT[1,`i']
}


foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
	foreach s in mean se pv obs wpv {
		matrix r1_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r1_`dep'_temp = r(table)
	matrix r1_`dep'_r2 = e(r2)
	matrix r1_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r1_`dep'_mean[1,`j'] = r1_`dep'_temp[1,`j']
	* standard error
	matrix r1_`dep'_se[1,`j'] = r1_`dep'_temp[2,`j']
	* p value
	matrix r1_`dep'_pv[1,`j'] = r1_`dep'_temp[4,`j']
	}


	
	
	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m1_`dep'_p = e(Pvals)
	matrix m1_`dep'_b = e(b)
	matrix m1_`dep'_v = e(V)
}


/*
gen missing_pts_pre = 0
gen missing_pts_post = 0
replace missing_pts_pre = 1 if pts_pre == .
replace missing_pts_post = 1 if pts_pre == .
replace pts_pre = 0 if pts_pre == .
replace pts_post = 0 if pts_post == .
*/

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_PTS = r(StatTotal)
}

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_PTS = r(StatTotal)
}

matrix n_dif1_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif1_PTS[1,`i'] = n_tr1_PTS[1,`i'] + n_ct1_PTS[1,`i']
}


matrix mean_dif1_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif1_PTS[1,`i'] = mean_tr1_PTS[1,`i'] - mean_ct1_PTS[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in pts_pre pts_post {
	foreach s in mean se pv obs wpv {
		matrix r1_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	matrix r1_`dep'_temp = r(table)
	matrix r1_`dep'_r2 = e(r2)
	matrix r1_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r1_`dep'_mean[1,`j'] = r1_`dep'_temp[1,`j']
	* standard error
	matrix r1_`dep'_se[1,`j'] = r1_`dep'_temp[2,`j']
	* p value
	matrix r1_`dep'_pv[1,`j'] = r1_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m1_`dep'_p = e(Pvals)
	matrix m1_`dep'_b = e(b)
	matrix m1_`dep'_v = e(V)
}






foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_rosen = r(StatTotal)
}

foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_rosen = r(StatTotal)
}

matrix n_dif1_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif1_rosen[1,`i'] = n_tr1_rosen[1,`i'] + n_ct1_rosen[1,`i']
}



matrix mean_dif1_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif1_rosen[1,`i'] = mean_tr1_rosen[1,`i'] - mean_ct1_rosen[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in rosen_pre rosen_post {
	foreach s in mean se pv obs wpv {
		matrix r1_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r1_`dep'_temp = r(table)
	matrix r1_`dep'_r2 = e(r2)
	matrix r1_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r1_`dep'_mean[1,`j'] = r1_`dep'_temp[1,`j']
	* standard error
	matrix r1_`dep'_se[1,`j'] = r1_`dep'_temp[2,`j']
	* p value
	matrix r1_`dep'_pv[1,`j'] = r1_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m1_`dep'_p = e(Pvals)
	matrix m1_`dep'_b = e(b)
	matrix m1_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_cpcs = r(StatTotal)
}

foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_cpcs = r(StatTotal)
}


matrix n_dif1_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif1_cpcs[1,`i'] = n_tr1_cpcs[1,`i'] + n_ct1_cpcs[1,`i']
}



matrix mean_dif1_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif1_cpcs[1,`i'] = mean_tr1_cpcs[1,`i'] - mean_ct1_cpcs[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in cpcs_pre cpcs_post {
	foreach s in mean se pv obs wpv {
		matrix r1_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r1_`dep'_temp = r(table)
	matrix r1_`dep'_r2 = e(r2)
	matrix r1_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r1_`dep'_mean[1,`j'] = r1_`dep'_temp[1,`j']
	* standard error
	matrix r1_`dep'_se[1,`j'] = r1_`dep'_temp[2,`j']
	* p value
	matrix r1_`dep'_pv[1,`j'] = r1_`dep'_temp[4,`j']
	}

	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m1_`dep'_p = e(Pvals)
	matrix m1_`dep'_b = e(b)
	matrix m1_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 1 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr1_demo = r(StatTotal)
}

foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 0 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct1_demo = r(StatTotal)
}



matrix n_dif1_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif1_demo[1,`i'] = n_tr1_demo[1,`i'] + n_ct1_demo[1,`i']
}


matrix mean_dif1_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif1_demo[1,`i'] = mean_tr1_demo[1,`i'] - mean_ct1_demo[1,`i']
}


foreach dep in gender age_pre age_sq_pre {
	foreach s in mean se pv obs wpv {
		matrix r1_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment , cluster(school_no)
	
	matrix r1_`dep'_temp = r(table)
	matrix r1_`dep'_r2 = e(r2)
	matrix r1_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r1_`dep'_mean[1,`j'] = r1_`dep'_temp[1,`j']
	* standard error
	matrix r1_`dep'_se[1,`j'] = r1_`dep'_temp[2,`j']
	* p value
	matrix r1_`dep'_pv[1,`j'] = r1_`dep'_temp[4,`j']
	}

	
	cgmwildboot_2 `dep' treatment , cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m1_`dep'_p = e(Pvals)
	matrix m1_`dep'_b = e(b)
	matrix m1_`dep'_v = e(V)
}










restore









* Test for PTS




preserve
drop if pts_pre == .
drop if pts_post == .






foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr2_DT = r(StatTotal)
}

foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct2_DT = r(StatTotal)
}



matrix n_dif2_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif2_DT[1,`i'] = n_tr2_DT[1,`i'] + n_ct2_DT[1,`i']
}


matrix mean_dif2_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif2_DT[1,`i'] = mean_tr2_DT[1,`i'] - mean_ct2_DT[1,`i']
}


foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
	foreach s in mean se pv obs wpv {
		matrix r2_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r2_`dep'_temp = r(table)
	matrix r2_`dep'_r2 = e(r2)
	matrix r2_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r2_`dep'_mean[1,`j'] = r2_`dep'_temp[1,`j']
	* standard error
	matrix r2_`dep'_se[1,`j'] = r2_`dep'_temp[2,`j']
	* p value
	matrix r2_`dep'_pv[1,`j'] = r2_`dep'_temp[4,`j']
	}


	
	
	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m2_`dep'_p = e(Pvals)
	matrix m2_`dep'_b = e(b)
	matrix m2_`dep'_v = e(V)
}







foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr2_PTS = r(StatTotal)
}

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct2_PTS = r(StatTotal)
}

matrix n_dif2_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif2_PTS[1,`i'] = n_tr2_PTS[1,`i'] + n_ct2_PTS[1,`i']
}


matrix mean_dif2_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif2_PTS[1,`i'] = mean_tr2_PTS[1,`i'] - mean_ct2_PTS[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in pts_pre pts_post {
	foreach s in mean se pv obs wpv {
		matrix r2_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	matrix r2_`dep'_temp = r(table)
	matrix r2_`dep'_r2 = e(r2)
	matrix r2_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r2_`dep'_mean[1,`j'] = r2_`dep'_temp[1,`j']
	* standard error
	matrix r2_`dep'_se[1,`j'] = r2_`dep'_temp[2,`j']
	* p value
	matrix r2_`dep'_pv[1,`j'] = r2_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m2_`dep'_p = e(Pvals)
	matrix m2_`dep'_b = e(b)
	matrix m2_`dep'_v = e(V)
}






foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr2_rosen = r(StatTotal)
}

foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct2_rosen = r(StatTotal)
}

matrix n_dif2_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif2_rosen[1,`i'] = n_tr2_rosen[1,`i'] + n_ct2_rosen[1,`i']
}



matrix mean_dif2_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif2_rosen[1,`i'] = mean_tr2_rosen[1,`i'] - mean_ct2_rosen[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in rosen_pre rosen_post {
	foreach s in mean se pv obs wpv {
		matrix r2_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r2_`dep'_temp = r(table)
	matrix r2_`dep'_r2 = e(r2)
	matrix r2_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r2_`dep'_mean[1,`j'] = r2_`dep'_temp[1,`j']
	* standard error
	matrix r2_`dep'_se[1,`j'] = r2_`dep'_temp[2,`j']
	* p value
	matrix r2_`dep'_pv[1,`j'] = r2_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m2_`dep'_p = e(Pvals)
	matrix m2_`dep'_b = e(b)
	matrix m2_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr2_cpcs = r(StatTotal)
}

foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct2_cpcs = r(StatTotal)
}


matrix n_dif2_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif2_cpcs[1,`i'] = n_tr2_cpcs[1,`i'] + n_ct2_cpcs[1,`i']
}



matrix mean_dif2_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif2_cpcs[1,`i'] = mean_tr2_cpcs[1,`i'] - mean_ct2_cpcs[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in cpcs_pre cpcs_post {
	foreach s in mean se pv obs wpv {
		matrix r2_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r2_`dep'_temp = r(table)
	matrix r2_`dep'_r2 = e(r2)
	matrix r2_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r2_`dep'_mean[1,`j'] = r2_`dep'_temp[1,`j']
	* standard error
	matrix r2_`dep'_se[1,`j'] = r2_`dep'_temp[2,`j']
	* p value
	matrix r2_`dep'_pv[1,`j'] = r2_`dep'_temp[4,`j']
	}

	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m2_`dep'_p = e(Pvals)
	matrix m2_`dep'_b = e(b)
	matrix m2_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 1 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr2_demo = r(StatTotal)
}

foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 0 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct2_demo = r(StatTotal)
}



matrix n_dif2_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif2_demo[1,`i'] = n_tr2_demo[1,`i'] + n_ct2_demo[1,`i']
}


matrix mean_dif2_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif2_demo[1,`i'] = mean_tr2_demo[1,`i'] - mean_ct2_demo[1,`i']
}


foreach dep in gender age_pre age_sq_pre {
	foreach s in mean se pv obs wpv {
		matrix r2_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment , cluster(school_no)
	
	matrix r2_`dep'_temp = r(table)
	matrix r2_`dep'_r2 = e(r2)
	matrix r2_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r2_`dep'_mean[1,`j'] = r2_`dep'_temp[1,`j']
	* standard error
	matrix r2_`dep'_se[1,`j'] = r2_`dep'_temp[2,`j']
	* p value
	matrix r2_`dep'_pv[1,`j'] = r2_`dep'_temp[4,`j']
	}

	
	cgmwildboot_2 `dep' treatment , cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m2_`dep'_p = e(Pvals)
	matrix m2_`dep'_b = e(b)
	matrix m2_`dep'_v = e(V)
}


restore















preserve
drop if missing_rosen_bl == 1 | missing_rosen_el == 1






foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr3_DT = r(StatTotal)
}

foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct3_DT = r(StatTotal)
}



matrix n_dif3_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif3_DT[1,`i'] = n_tr3_DT[1,`i'] + n_ct3_DT[1,`i']
}


matrix mean_dif3_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif3_DT[1,`i'] = mean_tr3_DT[1,`i'] - mean_ct3_DT[1,`i']
}


foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
	foreach s in mean se pv obs wpv {
		matrix r3_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r3_`dep'_temp = r(table)
	matrix r3_`dep'_r2 = e(r2)
	matrix r3_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r3_`dep'_mean[1,`j'] = r3_`dep'_temp[1,`j']
	* standard error
	matrix r3_`dep'_se[1,`j'] = r3_`dep'_temp[2,`j']
	* p value
	matrix r3_`dep'_pv[1,`j'] = r3_`dep'_temp[4,`j']
	}


	
	
	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m3_`dep'_p = e(Pvals)
	matrix m3_`dep'_b = e(b)
	matrix m3_`dep'_v = e(V)
}







foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr3_PTS = r(StatTotal)
}

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct3_PTS = r(StatTotal)
}

matrix n_dif3_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif3_PTS[1,`i'] = n_tr3_PTS[1,`i'] + n_ct3_PTS[1,`i']
}


matrix mean_dif3_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif3_PTS[1,`i'] = mean_tr3_PTS[1,`i'] - mean_ct3_PTS[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in pts_pre pts_post {
	foreach s in mean se pv obs wpv {
		matrix r3_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	matrix r3_`dep'_temp = r(table)
	matrix r3_`dep'_r2 = e(r2)
	matrix r3_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r3_`dep'_mean[1,`j'] = r3_`dep'_temp[1,`j']
	* standard error
	matrix r3_`dep'_se[1,`j'] = r3_`dep'_temp[2,`j']
	* p value
	matrix r3_`dep'_pv[1,`j'] = r3_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m3_`dep'_p = e(Pvals)
	matrix m3_`dep'_b = e(b)
	matrix m3_`dep'_v = e(V)
}






foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr3_rosen = r(StatTotal)
}

foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct3_rosen = r(StatTotal)
}

matrix n_dif3_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif3_rosen[1,`i'] = n_tr3_rosen[1,`i'] + n_ct3_rosen[1,`i']
}



matrix mean_dif3_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif3_rosen[1,`i'] = mean_tr3_rosen[1,`i'] - mean_ct3_rosen[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in rosen_pre rosen_post {
	foreach s in mean se pv obs wpv {
		matrix r3_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r3_`dep'_temp = r(table)
	matrix r3_`dep'_r2 = e(r2)
	matrix r3_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r3_`dep'_mean[1,`j'] = r3_`dep'_temp[1,`j']
	* standard error
	matrix r3_`dep'_se[1,`j'] = r3_`dep'_temp[2,`j']
	* p value
	matrix r3_`dep'_pv[1,`j'] = r3_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m3_`dep'_p = e(Pvals)
	matrix m3_`dep'_b = e(b)
	matrix m3_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr3_cpcs = r(StatTotal)
}

foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct3_cpcs = r(StatTotal)
}


matrix n_dif3_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif3_cpcs[1,`i'] = n_tr3_cpcs[1,`i'] + n_ct3_cpcs[1,`i']
}



matrix mean_dif3_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif3_cpcs[1,`i'] = mean_tr3_cpcs[1,`i'] - mean_ct3_cpcs[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in cpcs_pre cpcs_post {
	foreach s in mean se pv obs wpv {
		matrix r3_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r3_`dep'_temp = r(table)
	matrix r3_`dep'_r2 = e(r2)
	matrix r3_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r3_`dep'_mean[1,`j'] = r3_`dep'_temp[1,`j']
	* standard error
	matrix r3_`dep'_se[1,`j'] = r3_`dep'_temp[2,`j']
	* p value
	matrix r3_`dep'_pv[1,`j'] = r3_`dep'_temp[4,`j']
	}

	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m3_`dep'_p = e(Pvals)
	matrix m3_`dep'_b = e(b)
	matrix m3_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 1 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr3_demo = r(StatTotal)
}

foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 0 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct3_demo = r(StatTotal)
}



matrix n_dif3_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif3_demo[1,`i'] = n_tr3_demo[1,`i'] + n_ct3_demo[1,`i']
}


matrix mean_dif3_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif3_demo[1,`i'] = mean_tr3_demo[1,`i'] - mean_ct3_demo[1,`i']
}


foreach dep in gender age_pre age_sq_pre {
	foreach s in mean se pv obs wpv {
		matrix r3_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r3_`dep'_temp = r(table)
	matrix r3_`dep'_r2 = e(r2)
	matrix r3_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r3_`dep'_mean[1,`j'] = r3_`dep'_temp[1,`j']
	* standard error
	matrix r3_`dep'_se[1,`j'] = r3_`dep'_temp[2,`j']
	* p value
	matrix r3_`dep'_pv[1,`j'] = r3_`dep'_temp[4,`j']
	}

	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m3_`dep'_p = e(Pvals)
	matrix m3_`dep'_b = e(b)
	matrix m3_`dep'_v = e(V)
}



restore




preserve
drop if missing_cpcs_bl == 1 | missing_cpcs_el == 1






foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr4_DT = r(StatTotal)
}

foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct4_DT = r(StatTotal)
}



matrix n_dif4_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif4_DT[1,`i'] = n_tr4_DT[1,`i'] + n_ct4_DT[1,`i']
}


matrix mean_dif4_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif4_DT[1,`i'] = mean_tr4_DT[1,`i'] - mean_ct4_DT[1,`i']
}


foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
	foreach s in mean se pv obs wpv {
		matrix r4_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r4_`dep'_temp = r(table)
	matrix r4_`dep'_r2 = e(r2)
	matrix r4_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r4_`dep'_mean[1,`j'] = r4_`dep'_temp[1,`j']
	* standard error
	matrix r4_`dep'_se[1,`j'] = r4_`dep'_temp[2,`j']
	* p value
	matrix r4_`dep'_pv[1,`j'] = r4_`dep'_temp[4,`j']
	}


	
	
	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m4_`dep'_p = e(Pvals)
	matrix m4_`dep'_b = e(b)
	matrix m4_`dep'_v = e(V)
}







foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr4_PTS = r(StatTotal)
}

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct4_PTS = r(StatTotal)
}

matrix n_dif4_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif4_PTS[1,`i'] = n_tr4_PTS[1,`i'] + n_ct4_PTS[1,`i']
}


matrix mean_dif4_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif4_PTS[1,`i'] = mean_tr4_PTS[1,`i'] - mean_ct4_PTS[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in pts_pre pts_post {
	foreach s in mean se pv obs wpv {
		matrix r4_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	matrix r4_`dep'_temp = r(table)
	matrix r4_`dep'_r2 = e(r2)
	matrix r4_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r4_`dep'_mean[1,`j'] = r4_`dep'_temp[1,`j']
	* standard error
	matrix r4_`dep'_se[1,`j'] = r4_`dep'_temp[2,`j']
	* p value
	matrix r4_`dep'_pv[1,`j'] = r4_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m4_`dep'_p = e(Pvals)
	matrix m4_`dep'_b = e(b)
	matrix m4_`dep'_v = e(V)
}






foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr4_rosen = r(StatTotal)
}

foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct4_rosen = r(StatTotal)
}

matrix n_dif4_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif4_rosen[1,`i'] = n_tr4_rosen[1,`i'] + n_ct4_rosen[1,`i']
}



matrix mean_dif4_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif4_rosen[1,`i'] = mean_tr4_rosen[1,`i'] - mean_ct4_rosen[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in rosen_pre rosen_post {
	foreach s in mean se pv obs wpv {
		matrix r4_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r4_`dep'_temp = r(table)
	matrix r4_`dep'_r2 = e(r2)
	matrix r4_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r4_`dep'_mean[1,`j'] = r4_`dep'_temp[1,`j']
	* standard error
	matrix r4_`dep'_se[1,`j'] = r4_`dep'_temp[2,`j']
	* p value
	matrix r4_`dep'_pv[1,`j'] = r4_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m4_`dep'_p = e(Pvals)
	matrix m4_`dep'_b = e(b)
	matrix m4_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr4_cpcs = r(StatTotal)
}

foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct4_cpcs = r(StatTotal)
}


matrix n_dif4_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif4_cpcs[1,`i'] = n_tr4_cpcs[1,`i'] + n_ct4_cpcs[1,`i']
}



matrix mean_dif4_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif4_cpcs[1,`i'] = mean_tr4_cpcs[1,`i'] - mean_ct4_cpcs[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in cpcs_pre cpcs_post {
	foreach s in mean se pv obs wpv {
		matrix r4_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r4_`dep'_temp = r(table)
	matrix r4_`dep'_r2 = e(r2)
	matrix r4_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r4_`dep'_mean[1,`j'] = r4_`dep'_temp[1,`j']
	* standard error
	matrix r4_`dep'_se[1,`j'] = r4_`dep'_temp[2,`j']
	* p value
	matrix r4_`dep'_pv[1,`j'] = r4_`dep'_temp[4,`j']
	}

	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m4_`dep'_p = e(Pvals)
	matrix m4_`dep'_b = e(b)
	matrix m4_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 1 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr4_demo = r(StatTotal)
}

foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 0 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct4_demo = r(StatTotal)
}



matrix n_dif4_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif4_demo[1,`i'] = n_tr4_demo[1,`i'] + n_ct4_demo[1,`i']
}


matrix mean_dif4_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif4_demo[1,`i'] = mean_tr4_demo[1,`i'] - mean_ct4_demo[1,`i']
}


foreach dep in gender age_pre age_sq_pre {
	foreach s in mean se pv obs wpv {
		matrix r4_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment , cluster(school_no)
	
	matrix r4_`dep'_temp = r(table)
	matrix r4_`dep'_r2 = e(r2)
	matrix r4_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r4_`dep'_mean[1,`j'] = r4_`dep'_temp[1,`j']
	* standard error
	matrix r4_`dep'_se[1,`j'] = r4_`dep'_temp[2,`j']
	* p value
	matrix r4_`dep'_pv[1,`j'] = r4_`dep'_temp[4,`j']
	}

	
	cgmwildboot_2 `dep' treatment , cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m4_`dep'_p = e(Pvals)
	matrix m4_`dep'_b = e(b)
	matrix m4_`dep'_v = e(V)
}


restore

















preserve
keep if  (DT_per_min_pre != . & DT_per_min_post != . ) | (pts_pre != . & pts_post != .) | (missing_rosen_bl != 1 & missing_rosen_el != 1) | (missing_cpcs_bl != 1 & missing_cpcs_el != 1)






foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr5_DT = r(StatTotal)
}

foreach j in n mean sd {
tabstat DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct5_DT = r(StatTotal)
}



matrix n_dif5_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif5_DT[1,`i'] = n_tr5_DT[1,`i'] + n_ct5_DT[1,`i']
}


matrix mean_dif5_DT = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif5_DT[1,`i'] = mean_tr5_DT[1,`i'] - mean_ct5_DT[1,`i']
}


foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
	foreach s in mean se pv obs wpv {
		matrix r5_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	
	matrix r5_`dep'_temp = r(table)
	matrix r5_`dep'_r2 = e(r2)
	matrix r5_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r5_`dep'_mean[1,`j'] = r5_`dep'_temp[1,`j']
	* standard error
	matrix r5_`dep'_se[1,`j'] = r5_`dep'_temp[2,`j']
	* p value
	matrix r5_`dep'_pv[1,`j'] = r5_`dep'_temp[4,`j']
	}


	
	
	
	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m5_`dep'_p = e(Pvals)
	matrix m5_`dep'_b = e(b)
	matrix m5_`dep'_v = e(V)
}







foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr5_PTS = r(StatTotal)
}

foreach j in n mean sd {
tabstat pts_pre pts_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct5_PTS = r(StatTotal)
}

matrix n_dif5_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif5_PTS[1,`i'] = n_tr5_PTS[1,`i'] + n_ct5_PTS[1,`i']
}


matrix mean_dif5_PTS = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif5_PTS[1,`i'] = mean_tr5_PTS[1,`i'] - mean_ct5_PTS[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in pts_pre pts_post {
	foreach s in mean se pv obs wpv {
		matrix r5_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)
	matrix r5_`dep'_temp = r(table)
	matrix r5_`dep'_r2 = e(r2)
	matrix r5_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r5_`dep'_mean[1,`j'] = r5_`dep'_temp[1,`j']
	* standard error
	matrix r5_`dep'_se[1,`j'] = r5_`dep'_temp[2,`j']
	* p value
	matrix r5_`dep'_pv[1,`j'] = r5_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m5_`dep'_p = e(Pvals)
	matrix m5_`dep'_b = e(b)
	matrix m5_`dep'_v = e(V)
}






foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr5_rosen = r(StatTotal)
}

foreach j in n mean sd {
tabstat rosen_pre rosen_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct5_rosen = r(StatTotal)
}

matrix n_dif5_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif5_rosen[1,`i'] = n_tr5_rosen[1,`i'] + n_ct5_rosen[1,`i']
}



matrix mean_dif5_rosen = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif5_rosen[1,`i'] = mean_tr5_rosen[1,`i'] - mean_ct5_rosen[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in rosen_pre rosen_post {
	foreach s in mean se pv obs wpv {
		matrix r5_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r5_`dep'_temp = r(table)
	matrix r5_`dep'_r2 = e(r2)
	matrix r5_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r5_`dep'_mean[1,`j'] = r5_`dep'_temp[1,`j']
	* standard error
	matrix r5_`dep'_se[1,`j'] = r5_`dep'_temp[2,`j']
	* p value
	matrix r5_`dep'_pv[1,`j'] = r5_`dep'_temp[4,`j']
	}


	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m5_`dep'_p = e(Pvals)
	matrix m5_`dep'_b = e(b)
	matrix m5_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 1, stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr5_cpcs = r(StatTotal)
}

foreach j in n mean sd {
tabstat cpcs_pre cpcs_post if treatment == 0, stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct5_cpcs = r(StatTotal)
}


matrix n_dif5_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif5_cpcs[1,`i'] = n_tr5_cpcs[1,`i'] + n_ct5_cpcs[1,`i']
}



matrix mean_dif5_cpcs = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif5_cpcs[1,`i'] = mean_tr5_cpcs[1,`i'] - mean_ct5_cpcs[1,`i']
}


*foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post DT_score_post DT_time_post {
*	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
*	matrix m_`dep'_p = e(Pvals)
*}

foreach dep in cpcs_pre cpcs_post {
	foreach s in mean se pv obs wpv {
		matrix r5_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment, cluster(school_no)

	matrix r5_`dep'_temp = r(table)
	matrix r5_`dep'_r2 = e(r2)
	matrix r5_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r5_`dep'_mean[1,`j'] = r5_`dep'_temp[1,`j']
	* standard error
	matrix r5_`dep'_se[1,`j'] = r5_`dep'_temp[2,`j']
	* p value
	matrix r5_`dep'_pv[1,`j'] = r5_`dep'_temp[4,`j']
	}

	cgmwildboot_2 `dep' treatment, cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m5_`dep'_p = e(Pvals)
	matrix m5_`dep'_b = e(b)
	matrix m5_`dep'_v = e(V)
}


foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 1 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_tr5_demo = r(StatTotal)
}

foreach j in n mean sd {
tabstat gender age_pre age_sq_pre if treatment == 0 , stat(`j') save
matrix list r(StatTotal)
matrix `j'_ct5_demo = r(StatTotal)
}



matrix n_dif5_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix n_dif5_demo[1,`i'] = n_tr5_demo[1,`i'] + n_ct5_demo[1,`i']
}


matrix mean_dif5_demo = J(1,6,.)
forvalues i = 1/6 {
	matrix mean_dif5_demo[1,`i'] = mean_tr5_demo[1,`i'] - mean_ct5_demo[1,`i']
}


foreach dep in gender age_pre age_sq_pre {
	foreach s in mean se pv obs wpv {
		matrix r5_`dep'_`s' = J(1,2,.)
	}

	reg `dep' treatment , cluster(school_no)
	
	matrix r5_`dep'_temp = r(table)
	matrix r5_`dep'_r2 = e(r2)
	matrix r5_`dep'_obs = e(N)


	foreach j in 1 2 {
	* beta
	matrix r5_`dep'_mean[1,`j'] = r5_`dep'_temp[1,`j']
	* standard error
	matrix r5_`dep'_se[1,`j'] = r5_`dep'_temp[2,`j']
	* p value
	matrix r5_`dep'_pv[1,`j'] = r5_`dep'_temp[4,`j']
	}

	
	cgmwildboot_2 `dep' treatment , cluster(school_no) bootcluster(school_no) null(0) reps(999) seed(1)
	matrix m5_`dep'_p = e(Pvals)
	matrix m5_`dep'_b = e(b)
	matrix m5_`dep'_v = e(V)
}


restore



















forvalues j = 1/5 {

foreach dep in DT_per_min_pre DT_score_pre DT_time_pre DT_per_min_post ///
DT_score_post DT_time_post pts_pre pts_post rosen_pre rosen_post ///
cpcs_pre cpcs_post gender age_pre age_sq_pre {


forvalues item = 1/1 {
		forvalues scale = 1/1 {
		if m`j'_`dep'_p[`item', `scale']<=0.01 {
			local s_`j'_`dep'_`item'`scale' %3s "***"
		}
		else if (m`j'_`dep'_p[`item', `scale']>0.01) & (m`j'_`dep'_p[`item', `scale']<=0.05) {
			local s_`j'_`dep'_`item'`scale' %2s "**"
		}
		else if (m`j'_`dep'_p[`item', `scale']>0.05) & (m`j'_`dep'_p[`item', `scale']<=0.10) {
			local s_`j'_`dep'_`item'`scale' %1s "*"
		}
		else {
			local s_`j'_`dep'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // foreach `dep' loop

} // forvalues `j' loop







tempname hh2
file open `hh2' using "$pardir/tableD1.tex", write replace
file write `hh2' "" _newline
file write `hh2' "% Date: `c(current_date)'" _newline
file write `hh2' "% Time: `c(current_time)'" _newline
file write `hh2' "" _newline


file write `hh2' "\begin{table}[t!]\footnotesize" _newline
file write `hh2' "  \centering" _newline
file write `hh2' "  \caption{Baseline Balance Test Results}" _newline
file write `hh2' "\label{tab:summary}" _newline
file write `hh2' "\scalebox{0.9}{" _newline
file write `hh2' "\begin{threeparttable}" _newline

file write `hh2' "\begin{tabular}{lcccc}\toprule\midrule" _newline




*file write `hh2' "\cmidrule{2-5} & &&&      \\" _newline

file write `hh2' " Dependent Variable &   Treatment &  Control  & Difference & N   \\\midrule" _newline

file write `hh2' "     &  &  &  &  \\" _newline

file write `hh2' "  \multicolumn{5}{l}{\textbf{Panel A: Balancing with respect to DT variables}} \\\midrule" _newline
file write `hh2' "    DT Score per min\textsuperscript{a}   & " %04.3f (mean_tr1_DT[1,1]) " &   " %04.3f (mean_ct1_DT[1,1]) " & " %04.3f (mean_dif1_DT[1,1]) `s_1_DT_per_min_pre_11' " & " (n_dif1_DT[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr1_DT[1,1]) "] &   [" %04.3f (sd_ct1_DT[1,1]) "] & (" %04.3f (r1_DT_per_min_pre_se[1,1])             ") &                     \\" _newline


file write `hh2' "    DT Score                              & " %04.3f (mean_tr1_DT[1,2]) " &   " %04.3f (mean_ct1_DT[1,2]) " & " %04.3f (mean_dif1_DT[1,2]) `s_1_DT_score_pre_11' " & " (n_dif1_DT[1,2]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr1_DT[1,2]) "] &   [" %04.3f (sd_ct1_DT[1,2]) "] & (" %04.3f (r1_DT_score_pre_se[1,1])             ") &                     \\" _newline


file write `hh2' "    DT Time                               & " %04.3f (mean_tr1_DT[1,3]) " &   " %04.3f (mean_ct1_DT[1,3]) " & " %04.3f (mean_dif1_DT[1,3]) `s_1_DT_time_pre_11' " & " (n_dif1_DT[1,3]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr1_DT[1,3]) "] &   [" %04.3f (sd_ct1_DT[1,3]) "] & (" %04.3f (r1_DT_time_pre_se[1,1])             ") &                     \\" _newline


file write `hh2' "    PTSII-C Score\textsuperscript{b}      & " %04.3f (mean_tr2_PTS[1,1]) " &   " %04.3f (mean_ct2_PTS[1,1]) " & " %04.3f (mean_dif2_PTS[1,1]) `s_2_pts_pre_11' " & " (n_dif2_PTS[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr2_PTS[1,1]) "] &   [" %04.3f (sd_ct2_PTS[1,1]) "] & (" %04.3f (r2_pts_pre_se[1,1])              ") &                      \\" _newline


file write `hh2' "    RSES Index\textsuperscript{c}               & " %04.3f (mean_tr3_rosen[1,1]) " &   " %04.3f (mean_ct3_rosen[1,1]) " & " %04.3f (mean_dif3_rosen[1,1]) `s_3_rosen_pre_11' " & " (n_dif3_rosen[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr3_rosen[1,1]) "] &   [" %04.3f (sd_ct3_rosen[1,1]) "] & (" %04.3f (r3_rosen_pre_se[1,1])                ") &                        \\" _newline


file write `hh2' "    CPCS Index\textsuperscript{c}               & " %04.3f (mean_tr4_cpcs[1,1]) " &   " %04.3f (mean_ct4_cpcs[1,1]) " & " %04.3f (mean_dif4_cpcs[1,1]) `s_4_cpcs_pre_11' " & " (n_dif4_cpcs[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr4_cpcs[1,1]) "] &   [" %04.3f (sd_ct4_cpcs[1,1]) "] & (" %04.3f (r4_cpcs_pre_se[1,1])               ") &                       \\" _newline


file write `hh2' "    Female                                & " %04.3f (mean_tr5_demo[1,1]) " &   " %04.3f (mean_ct5_demo[1,1]) " & " %04.3f (mean_dif5_demo[1,1]) `s_5_gender_11' " & " (n_dif5_demo[1,1]) " \\" _newline
file write `hh2' "    									    & [" %04.3f (sd_tr5_demo[1,1]) "] &   [" %04.3f (sd_ct5_demo[1,1]) "] & (" %04.3f (r5_gender_se[1,1])               ") &                       \\" _newline


file write `hh2' "    Age                                   & " %04.3f (mean_tr5_demo[1,2]) " &   " %04.3f (mean_ct5_demo[1,2]) " & " %04.3f (mean_dif5_demo[1,2]) `s_5_age_pre_11' " & " (n_dif5_demo[1,2]) " \\ " _newline
file write `hh2' "    									    & [" %04.3f (sd_tr5_demo[1,2]) "] &   [" %04.3f (sd_ct5_demo[1,2]) "] & (" %04.3f (r5_age_pre_se[1,1])               ") &                       \\" _newline


file write `hh2' "    Age Squared                            & " %04.3f (mean_tr5_demo[1,3]) " &   " %04.3f (mean_ct5_demo[1,3]) " & " %04.3f (mean_dif5_demo[1,3]) `s_5_age_sq_pre_1' " & " (n_dif5_demo[1,3]) " \\ " _newline
file write `hh2' "    									    & [" %04.3f (sd_tr5_demo[1,3]) "] &   [" %04.3f (sd_ct5_demo[1,3]) "] & (" %04.3f (r5_age_sq_pre_se[1,1])               ") &                       \\\midrule\bottomrule" _newline







file write `hh2' "\end{tabular}" _newline
file write `hh2' "\begin{tablenotes}" _newline
file write `hh2' "\item Notes: Standard deviations are shown in brackets. Asymptotic standard errors are shown in parentheses and are clustered at the school level." _newline

file write `hh2' "\item \textsuperscript{a}: DT Score per min stands for math Diagnostic Test scores per minute." _newline

file write `hh2' "\item \textsuperscript{b}: PTSII-C Score stands for the math proficiency test scores." _newline
file write `hh2' "\item \textsuperscript{c}: The Proficiency Test of Self Learning is based on 27 survey questions, of which ten are consistent with the Children's Perceived Competence Scale (CPCS Index) and eight with the Rosenberg Self-Esteem Scale (RSES Index). For each of the non-cognitive type questions, see Appendix~\ref{AppB}." _newline
file write `hh2' "\end{tablenotes}" _newline
file write `hh2' "\end{threeparttable}" _newline
file write `hh2' "}" _newline
file write `hh2' "\label{tab:addlabel}%" _newline
file write `hh2' "\end{table}" _newline

file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline

file close `hh2'
















